package solutions;

/*

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?

*/


public class Euler016 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		final int DIGITS = 302;
		final int EXPONENT = 1000;
		
		int[] result = new int[DIGITS];
		
		result[DIGITS - 1] = 2;
		for(int i = 1; i < EXPONENT; i++){
			
			int carry = 0;
			for(int j = result.length - 1; j >= 0; j--){
				int total = result[j] * 2 + carry;
				result[j] = total > 9 ? total % 10 : total;
				carry = total / 10;
			}
		}
		
		long answer = 0;
		for(int number : result)
			answer += number;
		
		System.out.println("Answer: " + answer);
	}

}
